﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace MyMusicPlay._4._0
{
    public class ViewBoard : BaseClass
    {
        private MainWindow _main;
        private Grid _grid;
        private static ViewBoard _this;
        private bool display = false;
        private ViewBoard child;//用来调用隐藏子类
        public ViewBoard(MainWindow main)
        {
            _main = main;
        }

        public virtual void Initialize()
        {
            _this = PlayApplication.GetModule<ViewBoard>();
            _grid = _main.ViewBoardGrid;
        }

        /// <param name="child">子类[为了实现点击背板时隐藏当前项]</param>
        public virtual void Show(ViewBoard child = null)
        {
            if (_this.display)
                return;
            if (child != null)
            {
                _this.child = child;
            }
            _this._grid.Visibility = System.Windows.Visibility.Visible;
            _this.display = true;
            SY_Library.Animate.Double(_this._grid, Grid.OpacityProperty, _this._grid.Opacity, 1, 100);
        }

        public virtual void Hidden()
        {
            if (!_this.display)
                return;
            _this.display = false;
            SY_Library.Animate.Double(_this._grid, Grid.OpacityProperty, _this._grid.Opacity, 0, 100);
            Task.Run(() =>
            {
                Task.Delay(120).Wait();
                _this._main.Dispatcher.Invoke(() => { _this._grid.Visibility = System.Windows.Visibility.Hidden; });
            });
        }

        public void InvokeChild()
        {
            if (child != null)
            {
                child.Hidden();
            }
        }

    }
}
